//
//  JKCellStoreProductListItem.m
//  chequanbao_ios
//
//  Created by 朱凯 on 2018/1/29.
//  Copyright © 2018年 com.itboye. All rights reserved.
//

#import "JKCellStoreProductListItem.h"

@implementation JKCellStoreProductListItem
{
    UIImageView *_iconView;     // 图片
    UILabel *_nameLabel;        // 名称
    UILabel *_descLabel;        // 描述
    UILabel *_normalPriceLabel; // 市场价
    UILabel *_priceLabel;       // 价格
    UILabel *_sellsLabel;       // 已售
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    _iconView = [UIImageView new];
    _iconView.image = DEFAULT_IMAGE;
    [self.contentView addSubview:_iconView];
    
    _priceLabel = [UILabel new];
    _priceLabel.backgroundColor = rgba(118, 197, 250, 1);
    _priceLabel.userInteractionEnabled = true;
    _priceLabel.text = @"19￥";
    _priceLabel.font = FONT(14);
    _priceLabel.textAlignment = NSTextAlignmentCenter;
    _priceLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:_priceLabel];
    
    _sellsLabel = [UILabel new];
    _sellsLabel.text = @"19￥";
    _sellsLabel.font = FONT(14);
    _sellsLabel.textAlignment = NSTextAlignmentCenter;
    _sellsLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:_sellsLabel];
    
    _nameLabel = [UILabel new];
    _nameLabel.text = @"商品名称";
    _nameLabel.font = FONT(15);
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    _nameLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:_nameLabel];
    
    _descLabel = [UILabel new];
    _descLabel.text = @"商品描述文字商品描述文字商品描述文字商品描述文字商品描述文字商品描述文字";
    _descLabel.font = FONT(14);
    _descLabel.textAlignment = NSTextAlignmentLeft;
    _descLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:_descLabel];
    
    _normalPriceLabel = [UILabel new];
    _normalPriceLabel.text = @"市场价28￥";
    _normalPriceLabel.font = FONT(14);
    _normalPriceLabel.textAlignment = NSTextAlignmentLeft;
    _normalPriceLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:_normalPriceLabel];
    
    
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(@15);
        make.bottom.equalTo(@-15);
        make.width.equalTo(_iconView.mas_height);
    }];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-15);
        make.width.equalTo(@70);
        make.height.equalTo(@25);
        make.centerY.equalTo(_iconView);
    }];
    [_sellsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-15);
        make.top.equalTo(_priceLabel.mas_bottom).offset(5);
    }];
    [_descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_iconView);
        make.left.equalTo(_iconView.mas_right).offset(10);
        make.right.lessThanOrEqualTo(_priceLabel.mas_left).offset(-5);
    }];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_descLabel);
        make.bottom.equalTo(_descLabel.mas_top).offset(-5);
    }];
    [_normalPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_descLabel);
        make.top.equalTo(_descLabel.mas_bottom).offset(5);
    }];
}
- (void)setDic:(NSDictionary *)dic {
    
    _dic = dic;
    
    
    /*
     "id": "2",
     "name": "商品22",
     "price1": "1100",
     "price2": "1000",
     "detail": "请问",
     "img": "1318",
     "notes": "11人付款",
     "create_time": "0",
     "update_time": "0",
     "status": "0",
     "discount": "0",
     "recommend": "1",
     "product_type": "2"
     */
    
    [_iconView setImageWithURL:[NSURL URLWithString:BOYE_PICTURE_VIEW_URL(dic[@"img"])] placeholderImage:DEFAULT_IMAGE completed:nil];
    _nameLabel.text = dic[@"name"];
    _descLabel.text = dic[@"detail"];
    _sellsLabel.text = dic[@"notes"];
    _normalPriceLabel.text = [NSString stringWithFormat:@"市场价：%.2lf￥", [dic[@"price1"] doubleValue] / 100];
    _priceLabel.text = [NSString stringWithFormat:@"%.2lf￥", [dic[@"price2"] doubleValue] / 100];
}

@end
